package com.janlei.controller;

import com.janlei.service.AmazonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * @ClassName AmazonController
 * @Description 访问器
 * @Author ZhanLei
 * @Date 2021/5/12 13:18
 */

@RestController
@RequestMapping("/1.0/s3")
public class AmazonController {
    private static final Logger logger = LoggerFactory.getLogger(AmazonController.class);
    @Autowired
    private AmazonService amazonService;

    @PostMapping("/upload")
    public void put() {
        String keyName = "upload.txt";
        String upload = amazonService.upload(keyName, keyName.getBytes());
        logger.info("--------upload---------{}", upload);
    }

    @GetMapping("/download")
    public void get() {
        String keyName = "upload.txt";
        byte[] object = amazonService.getObject(keyName);
        String res = Arrays.toString(object);
        logger.info("--------upload---------{}", res);
    }
}
